package xstr

import "golang.org/x/crypto/bcrypt"

// GeneratePasswordHash 生成密码哈希
func GeneratePasswordHash(password string) (hash string, err error) {
	passwordHash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
	if err != nil {
		return "", err
	}
	return string(passwordHash), nil
}

// IsPasswordSame 判断两个密码是否一致
func IsPasswordSame(hashedPasswordStr, passwordStr string) bool {
	return bcrypt.CompareHashAndPassword([]byte(hashedPasswordStr), []byte(passwordStr)) == nil
}
